package ntd.util.config.common.bo;

import com.ejlchina.searcher.SearchResult;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageBO<T> {

    @Schema(description = "响应列表数据对象")
    public List<T> records = new ArrayList<>();
    @Schema(description = "数据总数量")
    private Number total = 0;

    public static <T> PageBO<T> transform(SearchResult<T> result) {
        PageBO<T> pageBO = new PageBO<>();
        pageBO.setTotal(result.getTotalCount());
        pageBO.setRecords(result.getDataList());
        return pageBO;
    }
}
